package com.icexxx.ice_browser;

import java.util.HashMap;
import java.util.Map;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Context {
    private static Map<String, JComponent> map = new HashMap<String, JComponent>();

    public static Map<String, JComponent> getMap() {
        return map;
    }

    public static void setMap(Map<String, JComponent> map) {
        Context.map = map;
    }

    public static JComponent put(String key, JComponent value) {
        return map.put(key, value);
    }

    public static JComponent get(String key) {
        return map.get(key);
    }

    public static JTextField getJTextField(String key) {
        JComponent jComponent = map.get(key);
        if (jComponent instanceof JTextField) {
            return (JTextField) jComponent;
        }
        return null;
    }

    public static JTextArea getJTextArea(String key) {
        JComponent jComponent = map.get(key);
        if (jComponent instanceof JTextArea) {
            return (JTextArea) jComponent;
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    public static JList<String> getJList(String key) {
        JComponent jComponent = map.get(key);
        if (jComponent instanceof JList) {
            return (JList<String>) jComponent;
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    public static JComboBox<String> getJComboBox(String key) {
        JComponent jComponent = map.get(key);
        if (jComponent instanceof JComboBox) {
            return (JComboBox<String>) jComponent;
        }
        return null;
    }

}
